<!--
**********************************************************
* @Author: 张小平
* @Date:   2024-05-01
* @Email:  qqshuqian@163.com
* @Last modified: 最后修改日期
* @Description: 文件描述
**********************************************************
-->
<template>
  <div>
    <el-input disabled prefix-icon="el-icon-location" v-model="address" />
    <div v-if="address" :class="isArea ? 'in' : 'error'">{{ isArea ? column.tip1 : column.tip2 }}</div>
  </div>
</template>

<script>
export default {
  name:"dingArea",
  inject: ['viewFormData'],
  props: ['column', 'value'],
  mounted() {
    console.log(this.column, this.value)
  },
  computed: {
    address() {
      const { addressType } = this.column
      return this.formateAddress(addressType, this.value)
    },
    isArea() {
      return this.value.isArea
    }
  },
  methods: {
    formateAddress(type, obj) {
      if (!obj) {
        return ''
      }
      const { province, city, district, road, address } = obj

      switch (type) {
        case 'province':
          return province || ''
        case 'city':
          return city ? `${province}${city}` : ''
        case 'district':
          return district ? `${province}${city}${district}` : ''
        case 'road':
          return road ? `${province}${city}${district}${road}` : ''
        default:
          return address || ''
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.error {
  color: #f48c12;
  padding-top: 5px;
}
.in {
  color: #07c160;
  padding-top: 5px;
}
</style>
